<template>
    <div class="pagebody">
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item> <i class="el-icon-lx-cascades"></i> 仓库区域管理 </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="search-box">
                <el-form>
                    <el-form-item label="仓库" prop="currentRepositoryid">
                        <el-select v-model="currentRepositoryid" @change="RepositoryChange" placeholder="请选择存储仓库">
                            <el-option v-for="item in RepositoryList" :key="item.id" :label="item.name" :value="item.id"> </el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="区域" prop="RegionList">
                        <el-button type="primary" icon="el-icon-plus" @click="handleAddRegion" v-if="currentRepositoryid != ''"
                            >新增区域</el-button
                        >
                        <el-radio-group v-model="currentRegionid" @change="RegionChange">
                            <el-radio-button v-for="item in RegionList" :key="item.id" :label="item.id">{{ item.name }} </el-radio-button>
                        </el-radio-group>
                        <el-button type="primary" icon="el-icon-edit" @click="handleEditRegion" v-if="currentRegionid != ''"
                            >编辑区域</el-button
                        >
                        <el-button type="primary" icon="el-icon-delete" @click="handleDeleteRegion" v-if="currentRegionid != ''"
                            >删除区域</el-button
                        >
                    </el-form-item>
                    <el-form-item label="货架" prop="ShelfList">
                        <el-button type="primary" icon="el-icon-plus" @click="handleAddShelf" v-if="currentRegionid != ''"
                            >新增货架</el-button
                        >
                        <el-radio-group v-model="currentShelfid" @change="ShelfChange">
                            <el-radio-button v-for="item in ShelfList" :key="item.id" :label="item.id">{{ item.name }}</el-radio-button>
                        </el-radio-group>
                        <el-button type="primary" icon="el-icon-edit" @click="handleEditShelf" v-if="currentShelfid != ''"
                            >编辑货架</el-button
                        >
                        <el-button type="primary" icon="el-icon-delete" @click="handleDeleteShelf" v-if="currentShelfid != ''"
                            >删除货架</el-button
                        >
                    </el-form-item>
                    <el-form-item label="层" prop="LayerList">
                        <el-button type="primary" icon="el-icon-plus" @click="handleAddLayer" v-if="currentShelfid != ''">新增层</el-button>
                        <el-radio-group v-model="currentLayerid" @change="LayerChange">
                            <el-radio-button v-for="item in LayerList" :key="item.id" :label="item.id">{{ item.name }}</el-radio-button>
                        </el-radio-group>
                        <el-button type="primary" icon="el-icon-edit" @click="handleEditLayer" v-if="currentLayerid != ''"
                            >编辑层</el-button
                        >
                        <el-button type="primary" icon="el-icon-delete" @click="handleDeleteLayer" v-if="currentLayerid != ''"
                            >删除层</el-button
                        >
                    </el-form-item>
                </el-form>
            </div>
            <!-- <div class="handle-box">
                <el-button type="primary" icon="el-icon-search" @click="handleSearch">搜索</el-button>
                <el-button type="primary" icon="el-icon-plus" @click="handleAddNew">新建</el-button>
            </div> -->
        </div>

        <el-dialog title="新建区域" :visible.sync="addregionVisible" width="60%">
            <el-form ref="form" :model="addregionform" :rules="addregionformRules" label-width="120px">
                <el-form-item label="仓库名称" prop="repositoryname">
                    <el-input v-model="addregionform.repositoryname" maxlength="20" show-word-limit disabled class="formInput"></el-input>
                </el-form-item>
                <el-form-item label="区域名称" prop="name">
                    <el-input v-model="addregionform.name" maxlength="20" show-word-limit clearable class="formInput"></el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="addregionVisible = false">取 消</el-button>
                <el-button type="primary" @click="saveaddregion">确 定</el-button>
            </span>
        </el-dialog>
        <el-dialog title="编辑区域" :visible.sync="editregionVisible" width="60%">
            <el-form ref="form" :model="editregionform" :rules="editregionformRules" label-width="120px">
                <el-form-item label="仓库名称" prop="repositoryname">
                    <el-input v-model="editregionform.repositoryname" maxlength="20" show-word-limit disabled class="formInput"></el-input>
                </el-form-item>
                <el-form-item label="区域名称" prop="name">
                    <el-input v-model="editregionform.name" maxlength="20" show-word-limit clearable class="formInput"></el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="editregionVisible = false">取 消</el-button>
                <el-button type="primary" @click="saveeditregion">确 定</el-button>
            </span>
        </el-dialog>
        <el-dialog title="删除区域" :visible.sync="deleteregionVisible" width="60%">
            <el-form ref="form" :model="deleteregionform" :rules="deleteregionformRules" label-width="120px">
                <el-form-item label="仓库名称" prop="repositoryname">
                    <el-input
                        v-model="deleteregionform.repositoryname"
                        maxlength="20"
                        show-word-limit
                        disabled
                        class="formInput"
                    ></el-input>
                </el-form-item>
                <el-form-item label="区域名称" prop="name">
                    <el-input v-model="deleteregionform.name" maxlength="20" show-word-limit disabled class="formInput"></el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="deleteregionVisible = false">取 消</el-button>
                <el-button type="primary" @click="savedeleteregion">确 定</el-button>
            </span>
        </el-dialog>

        <el-dialog title="新建货架" :visible.sync="addshelfVisible" width="60%">
            <el-form ref="form" :model="addshelfform" :rules="addshelfformRules" label-width="120px">
                <el-form-item label="仓库名称" prop="repositoryname">
                    <el-input v-model="addshelfform.repositoryname" maxlength="20" show-word-limit disabled class="formInput"></el-input>
                </el-form-item>
                <el-form-item label="区域名称" prop="repositoryregionname">
                    <el-input
                        v-model="addshelfform.repositoryregionname"
                        maxlength="20"
                        show-word-limit
                        disabled
                        class="formInput"
                    ></el-input>
                </el-form-item>
                <el-form-item label="货架名称" prop="name">
                    <el-input v-model="addshelfform.name" maxlength="20" show-word-limit clearable class="formInput"></el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="addshelfVisible = false">取 消</el-button>
                <el-button type="primary" @click="saveaddshelf">确 定</el-button>
            </span>
        </el-dialog>
        <el-dialog title="删除货架" :visible.sync="deleteshelfVisible" width="60%">
            <el-form ref="form" :model="deleteshelfform" :rules="deleteshelfformRules" label-width="120px">
                <el-form-item label="仓库名称" prop="repositoryname">
                    <el-input v-model="deleteshelfform.repositoryname" maxlength="20" show-word-limit disabled class="formInput"></el-input>
                </el-form-item>
                <el-form-item label="区域名称" prop="repositoryregionname">
                    <el-input
                        v-model="deleteshelfform.repositoryregionname"
                        maxlength="20"
                        show-word-limit
                        disabled
                        class="formInput"
                    ></el-input>
                </el-form-item>
                <el-form-item label="货架名称" prop="name">
                    <el-input v-model="deleteshelfform.name" maxlength="20" show-word-limit disabled class="formInput"></el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="deleteshelfVisible = false">取 消</el-button>
                <el-button type="primary" @click="savedeleteshelf">确 定</el-button>
            </span>
        </el-dialog>

        <el-dialog title="编辑货架" :visible.sync="editshelfVisible" width="60%">
            <el-form ref="form" :model="editshelfform" :rules="editshelfformRules" label-width="120px">
                <el-form-item label="仓库名称" prop="repositoryname">
                    <el-input v-model="editshelfform.repositoryname" maxlength="20" show-word-limit disabled class="formInput"></el-input>
                </el-form-item>
                <el-form-item label="区域名称" prop="repositoryregionname">
                    <el-input
                        v-model="editshelfform.repositoryregionname"
                        maxlength="20"
                        show-word-limit
                        disabled
                        class="formInput"
                    ></el-input>
                </el-form-item>
                <el-form-item label="货架名称" prop="name">
                    <el-input v-model="editshelfform.name" maxlength="20" show-word-limit clearable class="formInput"></el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="editshelfVisible = false">取 消</el-button>
                <el-button type="primary" @click="saveeditshelf">确 定</el-button>
            </span>
        </el-dialog>

        <el-dialog title="新建层" :visible.sync="addlayerVisible" width="60%">
            <el-form ref="form" :model="addlayerform" :rules="addlayerformRules" label-width="120px">
                <el-form-item label="仓库名称" prop="repositoryname">
                    <el-input v-model="addlayerform.repositoryname" maxlength="20" show-word-limit disabled class="formInput"></el-input>
                </el-form-item>
                <el-form-item label="区域名称" prop="repositoryregionname">
                    <el-input
                        v-model="addlayerform.repositoryregionname"
                        maxlength="20"
                        show-word-limit
                        disabled
                        class="formInput"
                    ></el-input>
                </el-form-item>
                <el-form-item label="货架名称" prop="repositoryshelfname">
                    <el-input
                        v-model="addlayerform.repositoryshelfname"
                        maxlength="20"
                        show-word-limit
                        disabled
                        class="formInput"
                    ></el-input>
                </el-form-item>
                <el-form-item label="层名称" prop="name">
                    <el-input v-model="addlayerform.name" maxlength="20" show-word-limit clearable class="formInput"></el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="addlayerVisible = false">取 消</el-button>
                <el-button type="primary" @click="saveaddlayer">确 定</el-button>
            </span>
        </el-dialog>
        <el-dialog title="删除层" :visible.sync="deletelayerVisible" width="60%">
            <el-form ref="form" :model="deletelayerform" :rules="deletelayerformRules" label-width="120px">
                <el-form-item label="仓库名称" prop="repositoryname">
                    <el-input v-model="deletelayerform.repositoryname" maxlength="20" show-word-limit disabled class="formInput"></el-input>
                </el-form-item>
                <el-form-item label="区域名称" prop="repositoryregionname">
                    <el-input
                        v-model="deletelayerform.repositoryregionname"
                        maxlength="20"
                        show-word-limit
                        disabled
                        class="formInput"
                    ></el-input>
                </el-form-item>
                <el-form-item label="货架名称" prop="repositoryshelfname">
                    <el-input
                        v-model="deletelayerform.repositoryshelfname"
                        maxlength="20"
                        show-word-limit
                        disabled
                        class="formInput"
                    ></el-input>
                </el-form-item>
                <el-form-item label="层名称" prop="name">
                    <el-input v-model="deletelayerform.name" maxlength="20" show-word-limit disabled class="formInput"></el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="deletelayerVisible = false">取 消</el-button>
                <el-button type="primary" @click="savedeletelayer">确 定</el-button>
            </span>
        </el-dialog>

        <el-dialog title="编辑层" :visible.sync="editlayerVisible" width="60%">
            <el-form ref="form" :model="editlayerform" :rules="editlayerformRules" label-width="120px">
                <el-form-item label="仓库名称" prop="repositoryname">
                    <el-input v-model="editlayerform.repositoryname" maxlength="20" show-word-limit disabled class="formInput"></el-input>
                </el-form-item>
                <el-form-item label="区域名称" prop="repositoryregionname">
                    <el-input
                        v-model="editlayerform.repositoryregionname"
                        maxlength="20"
                        show-word-limit
                        disabled
                        class="formInput"
                    ></el-input>
                </el-form-item>
                <el-form-item label="货架名称" prop="repositoryshelfname">
                    <el-input
                        v-model="editlayerform.repositoryshelfname"
                        maxlength="20"
                        show-word-limit
                        disabled
                        class="formInput"
                    ></el-input>
                </el-form-item>
                <el-form-item label="层名称" prop="name">
                    <el-input v-model="editlayerform.name" maxlength="20" show-word-limit clearable class="formInput"></el-input>
                </el-form-item>
            </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="editlayerVisible = false">取 消</el-button>
                <el-button type="primary" @click="saveeditlayer">确 定</el-button>
            </span>
        </el-dialog>
    </div>
</template>

<script>
import API from '../../../api/index'; //读入restfulAPI
import StringTool from '../../../utils/StringTool';
import JSTool from '../../../utils/JSTool';
import dataTable from './dataTable';

export default {
    name: 'repositoryRegionManage',
    mixins: [dataTable],

    data() {
        return {
            addregionVisible: false,
            editregionVisible: false,
            deleteregionVisible: false,
            addshelfVisible: false,
            editshelfVisible: false,
            deleteshelfVisible: false,
            addlayerVisible: false,
            editlayerVisible: false,
            deletelayerVisible: false,
            RepositoryList: [],
            RegionList: [],
            ShelfList: [],
            LayerList: [],
            currentRepositoryid: '',
            currentRepositoryname: '',
            currentRegionid: '',
            currentRegionname: '',
            currentShelfid: '',
            currentShelfname: '',
            currentLayerid: '',
            currentLayername: '',
            addregionform: {
                repositoryid: '',
                repositoryname: '',
                name: '',
                order: 0
            },
            addregionformRules: {},
            editregionform: {
                repositoryid: '',
                repositoryname: '',
                name: '',
                id: ''
            },
            editregionformRules: {},
            deleteregionform: {
                id: '',
                name: '',
                repositoryid: '',
                repositoryname: ''
            },
            deleteregionformRules: {},
            addshelfform: {
                repositoryid: '',
                repositoryname: '',
                repositoryregionid: '',
                repositoryregionname: '',
                name: '',
                order: 0
            },
            addshelfformRules: {},
            editshelfform: {
                repositoryid: '',
                repositoryname: '',
                repositoryregionid: '',
                repositoryregionname: '',
                name: '',
                id: ''
            },
            editshelfformRules: {},
            deleteshelfform: {
                repositoryid: '',
                repositoryname: '',
                repositoryregionid: '',
                repositoryregionname: '',
                name: '',
                id: ''
            },
            deleteshelfformRules: {},
            addlayerform: {
                repositoryid: '',
                repositoryname: '',
                repositoryregionid: '',
                repositoryregionname: '',
                repositoryshelfid: '',
                repositoryshelfname: '',
                name: '',
                order: 0
            },
            addlayerformRules: {},
            editlayerform: {
                repositoryid: '',
                repositoryname: '',
                repositoryregionid: '',
                repositoryregionname: '',
                repositoryshelfid: '',
                repositoryshelfname: '',
                name: '',
                id: ''
            },
            editlayerformRules: {},
            deletelayerform: {
                repositoryid: '',
                repositoryname: '',
                repositoryregionid: '',
                repositoryregionname: '',
                repositoryshelfid: '',
                repositoryshelfname: '',
                name: '',
                id: ''
            },
            deletelayerformRules: {}
        };
    },
    created() {
        this.init();
    },
    mounted() {},
    methods: {
        //页面初始化
        init() {
            API.StandardDoWith(API.Repository.Get({ pageSize: 99, status: 1 }), this, {
                success: (detail) => {
                    this.RepositoryList = detail.list;
                }
            });
        },
        getData() {
            this.RepositoryList = [];
            API.StandardDoWith(API.Repository.Get({ pageSize: 99, status: 1 }), this, {
                success: (detail) => {
                    this.RepositoryList = detail.list;
                }
            });
        },
        RepositoryChange(val) {
            for (let res of this.RepositoryList) {
                if (res.id == this.currentRepositoryid) {
                    this.currentRepositoryname = res.name;
                    break;
                }
            }
            //获取仓库区域
            this.getRepositoryRegion();
        },
        RegionChange(val) {
            for (let region of this.RegionList) {
                if (region.id == this.currentRegionid) {
                    this.currentRegionname = region.name;
                    break;
                }
            }
            this.getRepositoryShelf();
        },
        ShelfChange(val) {
            for (let shelf of this.ShelfList) {
                if (shelf.id == this.currentShelfid) {
                    this.currentShelfname = shelf.name;
                    break;
                }
            }
            this.getRepositoryLayer();
        },
        LayerChange(val) {
            for (let layer of this.LayerList) {
                if (layer.id == this.currentLayerid) {
                    this.currentLayername = layer.name;
                    break;
                }
            }
        },

        getRepositoryRegion() {
            this.RegionList = [];
            this.ShelfList = [];
            this.LayerList = [];
            this.currentRegionid = '';
            this.currentRegionname = '';
            this.currentShelfid = '';
            this.currentShelfname = '';
            this.currentLayerid = '';
            this.currentLayername = '';
            for (let rep of this.RepositoryList) {
                if (rep.id === this.currentRepositoryid) {
                    this.RegionList = rep.regions;
                }
            }
            // console.log(this.RepositoryList);
        },
        refreshRepositoryRegion() {
            this.RepositoryList = [];
            API.StandardDoWith(API.Repository.Get({ pageSize: 99, status: 1 }), this, {
                success: (detail) => {
                    this.RepositoryList = detail.list;
                    this.RegionList = [];
                    this.ShelfList = [];
                    this.LayerList = [];
                    this.currentShelfid = '';
                    this.currentShelfname = '';
                    this.currentLayerid = '';
                    this.currentLayername = '';
                    for (let rep of this.RepositoryList) {
                        if (rep.id === this.currentRepositoryid) {
                            this.RegionList = rep.regions;
                        }
                    }
                    if (this.currentRegionid) {
                        for (let region of this.RegionList) {
                            if (region.id === this.currentRegionid) {
                                this.ShelfList = region.shelfs;
                            }
                        }
                    }
                }
            });
        },
        getRepositoryShelf() {
            this.ShelfList = [];
            this.LayerList = [];
            this.currentShelfid = '';
            this.currentShelfname = '';
            this.currentLayerid = '';
            this.currentLayername = '';
            for (let rep of this.RepositoryList) {
                if (rep.id === this.currentRepositoryid) {
                    this.RegionList = rep.regions;
                }
            }
            for (let region of this.RegionList) {
                if (region.id === this.currentRegionid) {
                    this.ShelfList = region.shelfs;
                }
            }
        },
        refreshRepositoryShelf() {
            this.RepositoryList = [];
            API.StandardDoWith(API.Repository.Get({ pageSize: 99, status: 1 }), this, {
                success: (detail) => {
                    this.RepositoryList = detail.list;
                    this.ShelfList = [];
                    this.LayerList = [];
                    this.currentLayerid = '';
                    this.currentLayername = '';

                    for (let rep of this.RepositoryList) {
                        if (rep.id === this.currentRepositoryid) {
                            this.RegionList = rep.regions;
                        }
                    }
                    for (let region of this.RegionList) {
                        if (region.id === this.currentRegionid) {
                            this.ShelfList = region.shelfs;
                        }
                    }
                    if (this.currentShelfid) {
                        for (let shelf of this.ShelfList) {
                            if (shelf.id === this.currentShelfid) {
                                this.LayerList = shelf.layers;
                            }
                        }
                    }
                }
            });
        },
        refreshRepositoryLayer() {
            this.RepositoryList = [];
            API.StandardDoWith(API.Repository.Get({ pageSize: 99, status: 1 }), this, {
                success: (detail) => {
                    this.RepositoryList = detail.list;
                    this.LayerList = [];
                    for (let rep of this.RepositoryList) {
                        if (rep.id === this.currentRepositoryid) {
                            this.RegionList = rep.regions;
                        }
                    }
                    for (let region of this.RegionList) {
                        if (region.id === this.currentRegionid) {
                            this.ShelfList = region.shelfs;
                        }
                    }
                    for (let shelf of this.ShelfList) {
                        if (shelf.id === this.currentShelfid) {
                            this.LayerList = shelf.layers;
                        }
                    }
                }
            });
        },
        getRepositoryLayer() {
            this.LayerList = [];
            this.currentLayerid = '';
            this.currentLayername = '';
            for (let rep of this.RepositoryList) {
                if (rep.id === this.currentRepositoryid) {
                    this.RegionList = rep.regions;
                }
            }
            for (let region of this.RegionList) {
                if (region.id === this.currentRegionid) {
                    this.ShelfList = region.shelfs;
                }
            }
            for (let shelf of this.ShelfList) {
                if (shelf.id === this.currentShelfid) {
                    this.LayerList = shelf.layers;
                }
            }
        },
        handleAddRegion() {
            if (this.currentRepositoryid == '') {
                this.$message.error(`请选择仓库`);
                return;
            }
            this.addregionform.repositoryid = this.currentRepositoryid;
            this.addregionform.repositoryname = this.currentRepositoryname;
            this.addregionform.order = this.RegionList.length + 1;
            this.addregionVisible = true;
        },
        handleDeleteRegion() {
            if (this.currentRepositoryid == '') {
                this.$message.error(`请选择仓库`);
                return;
            }
            if (this.currentRegionid == '') {
                this.$message.error(`请选择需删除的区域`);
                return;
            }
            this.deleteregionform.repositoryid = this.currentRepositoryid;
            this.deleteregionform.repositoryname = this.currentRepositoryname;
            this.deleteregionform.id = this.currentRegionid;
            this.deleteregionform.name = this.currentRegionname;
            this.deleteregionVisible = true;
        },
        handleEditRegion() {
            if (this.currentRepositoryid == '') {
                this.$message.error(`请选择仓库`);
                return;
            }
            if (this.currentRegionid == '') {
                this.$message.error(`请选择需要编辑的区域`);
                return;
            }
            this.editregionform.repositoryid = this.currentRepositoryid;
            this.editregionform.repositoryname = this.currentRepositoryname;
            this.editregionform.id = this.currentRegionid;
            this.editregionform.name = this.currentRegionname;
            this.editregionVisible = true;
        },
        handleEditShelf() {
            if (this.currentRepositoryid == '') {
                this.$message.error(`请选择仓库`);
                return;
            }
            if (this.currentRegionid == '') {
                this.$message.error(`请选择需要编辑的区域`);
                return;
            }

            if (this.currentShelfid == '') {
                this.$message.error(`请选择需要编辑的货架`);
                return;
            }
            this.editshelfform.repositoryregionid = this.currentRegionid;
            this.editshelfform.repositoryregionname = this.currentRegionname;
            this.editshelfform.repositoryid = this.currentRepositoryid;
            this.editshelfform.repositoryname = this.currentRepositoryname;
            this.editshelfform.id = this.currentShelfid;
            this.editshelfform.name = this.currentShelfname;
            this.editshelfVisible = true;
        },
        handleAddShelf() {
            if (this.currentRepositoryid == '') {
                this.$message.error(`请选择仓库`);
                return;
            }
            if (this.currentRegionid == '') {
                this.$message.error(`请选择区域`);
                return;
            }
            this.addshelfform.repositoryid = this.currentRepositoryid;
            this.addshelfform.repositoryname = this.currentRepositoryname;
            this.addshelfform.repositoryregionid = this.currentRegionid;
            this.addshelfform.repositoryregionname = this.currentRegionname;
            this.addshelfform.order = this.ShelfList.length + 1;
            this.addshelfVisible = true;
        },
        handleDeleteShelf() {
            if (this.currentRepositoryid == '') {
                this.$message.error(`请选择仓库`);
                return;
            }
            if (this.currentRegionid == '') {
                this.$message.error(`请选择区域`);
                return;
            }
            if (this.currentShelfid == '') {
                this.$message.error(`请选择需要删除货架`);
                return;
            }
            this.deleteshelfform.id = this.currentShelfid;
            this.deleteshelfform.name = this.currentShelfname;
            this.deleteshelfform.repositoryid = this.currentRepositoryid;
            this.deleteshelfform.repositoryname = this.currentRepositoryname;
            this.deleteshelfform.repositoryregionid = this.currentRegionid;
            this.deleteshelfform.repositoryregionname = this.currentRegionname;
            this.deleteshelfVisible = true;
        },
        handleEditLayer() {
            if (this.currentRepositoryid == '') {
                this.$message.error(`请选择仓库`);
                return;
            }
            if (this.currentRegionid == '') {
                this.$message.error(`请选择需要编辑的区域`);
                return;
            }

            if (this.currentShelfid == '') {
                this.$message.error(`请选择需要编辑的货架`);
                return;
            }
            if (this.currentLayerid == '') {
                this.$message.error(`请选择需要编辑的层`);
                return;
            }
            this.editlayerform.repositoryregionid = this.currentRegionid;
            this.editlayerform.repositoryregionname = this.currentRegionname;
            this.editlayerform.repositoryid = this.currentRepositoryid;
            this.editlayerform.repositoryname = this.currentRepositoryname;
            this.editlayerform.repositoryshelfid = this.currentShelfid;
            this.editlayerform.repositoryshelfname = this.currentShelfname;
            this.editlayerform.id = this.currentLayerid;
            this.editlayerform.name = this.currentLayername;
            this.editlayerVisible = true;
        },
        handleAddLayer() {
            if (this.currentRepositoryid == '') {
                this.$message.error(`请选择仓库`);
                return;
            }
            if (this.currentRegionid == '') {
                this.$message.error(`请选择区域`);
                return;
            }
            if (this.currentShelfid == '') {
                this.$message.error(`请选择货架`);
                return;
            }
            this.addlayerform.repositoryid = this.currentRepositoryid;
            this.addlayerform.repositoryname = this.currentRepositoryname;
            this.addlayerform.repositoryregionid = this.currentRegionid;
            this.addlayerform.repositoryregionname = this.currentRegionname;
            this.addlayerform.repositoryshelfid = this.currentShelfid;
            this.addlayerform.repositoryshelfname = this.currentShelfname;
            this.addlayerform.order = this.LayerList.length + 1;
            this.addlayerVisible = true;
        },
        handleDeleteLayer() {
            if (this.currentRepositoryid == '') {
                this.$message.error(`请选择仓库`);
                return;
            }
            if (this.currentRegionid == '') {
                this.$message.error(`请选择区域`);
                return;
            }
            if (this.currentShelfid == '') {
                this.$message.error(`请选择货架`);
                return;
            }
            if (this.currentLayerid == '') {
                this.$message.error(`请选择需要删除的层`);
                return;
            }
            this.deletelayerform.id = this.currentLayerid;
            this.deletelayerform.name = this.currentLayername;
            this.deletelayerform.repositoryid = this.currentRepositoryid;
            this.deletelayerform.repositoryname = this.currentRepositoryname;
            this.deletelayerform.repositoryregionid = this.currentRegionid;
            this.deletelayerform.repositoryregionname = this.currentRegionname;
            this.deletelayerform.repositoryshelfid = this.currentShelfid;
            this.deletelayerform.repositoryshelfname = this.currentShelfname;
            this.deletelayerVisible = true;
        },
        saveaddregion() {
            let postForm = JSTool.DeepClone(this.addregionform);
            API.StandardDoWith(API.RepositoryRegion.Post(postForm), this, {
                success: (detail) => {
                    this.$message.success(`成功添加区域`);
                    this.addregionVisible = false;
                    this.currentRegionid = '';
                    this.currentRegionname = '';
                    this.refreshRepository();
                }
            });
            this.getData();
            this.refreshRepositoryRegion();
        },
        savedeleteregion() {
            API.StandardDoWith(API.RepositoryRegion.Delete({ id: this.deleteregionform.id }), this, {
                success: (detail) => {
                    this.$message.success(`成功删除区域`);
                    this.deleteregionVisible = false;
                    this.currentRegionid = '';
                    this.currentRegionname = '';
                    this.refreshRepositoryRegion();
                }
            });
        },
        saveeditregion() {
            let postForm = JSTool.DeepClone(this.editregionform);
            API.StandardDoWith(API.RepositoryRegion.Put(postForm), this, {
                success: (detail) => {
                    this.$message.success(`成功修改区域`);
                    this.editregionVisible = false;
                    this.refreshRepositoryRegion();
                }
            });
        },
        saveaddshelf() {
            let postForm = JSTool.DeepClone(this.addshelfform);
            API.StandardDoWith(API.RepositoryShelf.Post(postForm), this, {
                success: (detail) => {
                    this.$message.success(`成功添加货架`);
                    this.addshelfVisible = false;
                    this.currentShelfid = '';
                    this.currentShelfname = '';
                    this.refreshRepositoryShelf();
                }
            });
        },
        savedeleteshelf() {
            API.StandardDoWith(API.RepositoryShelf.Delete({ id: this.deleteshelfform.id }), this, {
                success: (detail) => {
                    this.$message.success(`成功删除货架`);
                    this.deleteshelfVisible = false;
                    this.currentShelfid = '';
                    this.currentShelfname = '';
                    this.refreshRepositoryShelf();
                }
            });
        },

        saveeditshelf() {
            let postForm = JSTool.DeepClone(this.editshelfform);
            API.StandardDoWith(API.RepositoryShelf.Put(postForm), this, {
                success: (detail) => {
                    this.$message.success(`成功修改货架`);
                    this.editshelfVisible = false;
                    this.refreshRepositoryShelf();
                }
            });
        },
        saveaddlayer() {
            let postForm = JSTool.DeepClone(this.addlayerform);
            API.StandardDoWith(API.RepositoryLayer.Post(postForm), this, {
                success: (detail) => {
                    this.$message.success(`成功添加层`);
                    this.addlayerVisible = false;
                    this.refreshRepositoryLayer();
                }
            });
        },
        savedeletelayer() {
            API.StandardDoWith(API.RepositoryLayer.Delete({ id: this.deletelayerform.id }), this, {
                success: (detail) => {
                    this.$message.success(`成功删除层`);
                    this.deletelayerVisible = false;
                    this.currentLayerid = '';
                    this.currentLayername = '';
                    this.refreshRepositoryLayer();
                }
            });
        },
        saveeditlayer() {
            let postForm = JSTool.DeepClone(this.editlayerform);
            API.StandardDoWith(API.RepositoryLayer.Put(postForm), this, {
                success: (detail) => {
                    this.$message.success(`成功修改层`);
                    this.editlayerVisible = false;
                    this.refreshRepositoryLayer();
                }
            });
        }
    }
};
</script>

<style scoped>
@import '../../../assets/css/dataTable.css';
.excel {
    width: 100%;
}
.excel table {
    margin: 0 auto;
    text-align: center;
    border: 1px solid gray;
}
.excel table tr td {
    margin: 5px 10px;
    padding: 5px;
    border: 1px solid gray;
}
</style>
